package com.cashmama.market.api.application.controller.picture;

import com.cashmama.market.api.application.controller.picture.response.AmazonS3TokenVO;
import com.cashmama.market.api.domain.oss.AmazonS3TokenService;
import com.cashmama.market.api.domain.vo.RequestLocalInfo;
import com.cashmama.market.api.infras.handler.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: market-api
 * @description
 * @author: frank
 * @create: 2020-09-27 23:53
 **/
@RestController
@RequestMapping("/amazon")
public class AmazonS3Controller {

    @Autowired
    private AmazonS3TokenService amazonS3TokenService;

    /**
     * 获取s3 token获取
     * @return
     */
    @RequestMapping(value = "/s3/token/get", method = RequestMethod.POST)
    public ApiResponse<AmazonS3TokenVO> getAmazonS3Token() {

        AmazonS3TokenService.AmazonS3TokenInfo amazonS3TokenInfo = amazonS3TokenService.assumeRole(RequestLocalInfo.getCurrentUser().getUserCode());
        return new ApiResponse<>(new AmazonS3TokenVO(amazonS3TokenInfo));
    }
}
